//
//  FQHomeBackgroundCollectionViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/7.
//

import UIKit

class FQHomeBackgroundCollectionViewCell: UICollectionViewCell {
    var model : FQHomeBackgroundModel! {
        didSet {
            
        }
    }
    var buttonBlock : (()->Void)? {
        didSet {
            scrollView.buttonBlock = buttonBlock
        }
    }
    let scrollView = FQAutoScrollView(buttonBlock: nil)

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let imageV = UIImageView(imageString: "home_background_1")
        contentView.addSubview(imageV)
        
        imageV.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
        }
        
        let backgroundImage = UIImageView(imageString: "home_background")
        backgroundImage.isUserInteractionEnabled = true
        contentView.addSubview(backgroundImage)
        
        backgroundImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(335~)
            make.height.equalTo(290)
            make.top.equalTo(NavigationContentTop + 10)
        }
        
        let titleLb = QMUILabel(font: .rSFont(16), textColor: .color51)
        titleLb.text = "最高可借(元)"
        backgroundImage.addSubview(titleLb)
        
        titleLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(32)
        }
        
        let amountLb = QMUILabel(font: .mSFont(54), textColor: .colorMain)
        amountLb.text = "200,000"
        backgroundImage.addSubview(amountLb)
        
        amountLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLb.snp.bottom).offset(16)
        }
        
        let rateLb = QMUILabel(font: .rSFont(14), textColor: .color102)
        rateLb.text = "年化利率(单利) 7.2%～24%"
        backgroundImage.addSubview(rateLb)
        
        rateLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(amountLb.snp.bottom).offset(8)
        }
        
        let activateBtn = QMUIFillButton(fill: .colorMain, titleTextColor: .white)
        activateBtn.titleLabel?.font = .mSFont(16)
        activateBtn.setTitle("激活额度", for: .normal)
        activateBtn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        backgroundImage.addSubview(activateBtn)
        
        activateBtn.snp.makeConstraints { make in
            make.left.equalTo(41)
            make.right.equalTo(-41)
            make.top.equalTo(rateLb.snp.bottom).offset(32)
            make.height.equalTo(42)
        }
        
        let tipLb = QMUILabel(font: .rSFont(12), textColor: .colorMake(193, 193, 193))
        tipLb.text = "— 理性贷款  合理消费 —"
        backgroundImage.addSubview(tipLb)
        
        tipLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-16)
        }
        
        let marqueeLb = FQMarqueeView("")
        addSubview(marqueeLb)
        
        marqueeLb.snp.makeConstraints { make in
            make.left.right.equalTo(backgroundImage)
            make.top.equalTo(backgroundImage.snp.bottom).offset(16)
            make.height.equalTo(40)
        }
        
        addSubview(scrollView)
        
        scrollView.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.top.equalTo(marqueeLb.snp.bottom).offset(10)
            make.height.equalTo(174~)
        }
    }
    
    @objc func buttonClick() {
        buttonBlock?()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
